package Doudizu;

import javax.smartcardio.Card;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class houtai {
   private List<info> Card=new ArrayList<>();
    public houtai(){

        List<info> Card=new ArrayList<>();
        this.Card=Card;
        String[] card={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        String[] color={"♠","♥","♦","♣"};
        int size=0;
        for (String s : card) {
            size++;
            for (String string : color) {
                info x = new info(s,string,size);
                Card.add(x);

            }
        }
        info x1 =new info("小王","",++size);
        info x2 =new info("大王","",++size);
        Collections.addAll(Card,x1,x2);
        System.out.println("新牌"+Card);

    }

    public void start() {
        Collections.shuffle(Card);
        System.out.println("洗牌后："+Card);
        List<info> libai=new ArrayList<>();
        List<info> lihei=new ArrayList<>();
        List<info> lihong=new ArrayList<>();
        for (int i = 0; i <Card.size()-3 ; i++) {
            if (i%3==0) {
                libai.add(Card.get(i));
            } else if (i%3==1) {
                lihei.add(Card.get(i));

            } else if (i%3==2) {
                lihong.add(Card.get(i));

            }
        }
        List<info> name=Card.subList(Card.size()-3,54);
        System.out.println("留的地主牌"+name);
        lihong.addAll(name);
        sortCard(libai);
        sortCard(lihei);
        sortCard(lihong);
        System.out.println("李白的牌："+libai);
        System.out.println("李黑的牌："+lihei);
        System.out.println("李红的牌："+lihong);
    }

    private void sortCard(List<info> Card) {
        Collections.sort(Card, new Comparator<info>() {
            @Override
            public int compare(info o1, info o2) {
                return o1.getSize()- o2.getSize();
            }
        });
    }
}
